package com.elastic.enums;


import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public enum PersonEnum {
    MALE(1,"男人", Man.class),
    FEMALE(0,"女人",Woman.class);

    private Integer code;

    private String name;


    private  Class<? extends Person> matchUtils;

    PersonEnum(Integer code, String name, Class<? extends Person> matchUtils) {
        this.code = code;
        this.name = name;
        this.matchUtils = matchUtils;
    }


    public static PersonEnum getPersonClass(Integer code){
        Map<Integer, PersonEnum> personEnumMap = Stream.of(values()).collect(Collectors.toMap(p -> p.getCode(), Function.identity()));
        PersonEnum personEnum = personEnumMap.get(code);

        if (personEnum == null){
            return null;
        }
        return personEnum;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Class<? extends Person> getMatchUtils() {
        return matchUtils;
    }

    public void setMatchUtils(Class<? extends Person> matchUtils) {
        this.matchUtils = matchUtils;
    }
}
